package com.hm.rabitmq.simple;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

/**
 * @author shishun.wang
 * @date 2016年12月8日 下午5:55:35
 * @version 1.0
 * @describe
 */
public class Sending {

	private final static String QUEUE_NAME = "10.0.0.10:SAMPLE_HELLO";

	public static void main(String[] args) throws Exception {
		for (int i = 0; i < 5; i++) {
			send();
			Thread.sleep(2000);
		}
	}

	private static void send() {
		try {
			ConnectionFactory factory = new ConnectionFactory();
			factory.setHost("115.28.66.183");

			Connection connection = factory.newConnection();
			Channel channel = connection.createChannel();

			channel.queueDeclare(QUEUE_NAME, false, false, false, null);

			String message = Sending.class.getName() + "Hello World! current time is " + System.currentTimeMillis();
			channel.basicPublish("", QUEUE_NAME, null, message.getBytes());
			System.out.println(" [x] Sent '" + message + "'");

			channel.close();
			connection.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
